﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

public class DriveableObject:MissionObject
{
    protected new DriveableObject.Type thisType;
    //number of millis a heavy object can be in a hazard before blowing up
    protected double hazardTimeLimit = 10000;
    protected double currHazardTime = 0;
    protected bool hazardThisFrame = false;

    /**
     * creates a CollidableObject at 'placement' of type 'type'.
     * initializes origin, and
     * type. This will set the SpawnPointer for this instance
     * to null.
     * @param type an instance of ObjectFactory.TypeEnum which
     * specifies what type of CollidableObject to create
     * @param placement the world x,y,z coordinates that define
     * where this instance is placed.
     * @see ObjectFactory.TypeEnum
     */
    public DriveableObject(DriveableObject.Type type, Vector3 placement)
        : base(type, placement)
    {
        thisType = type;
    }

    public override void destroy(CollidableObject cobj)
    {
        if (cobj is DangerousObject)
        {
            hazardThisFrame = true;
            if (currHazardTime > hazardTimeLimit)
            {
                base.destroy(cobj);
            }
        }
    }

    public override void update(double elapsed)
    {
        hazardThisFrame = false;
        base.update(elapsed);
        if (hazardThisFrame)
        {
            currHazardTime += elapsed;
        }
        else
        {
            currHazardTime = 0;
        }
    }

    public new class Type : MissionObject.Type
    {
        //driveable objects:
        public static readonly Type Car = new Type();
        public static readonly Type Truck = new Type(
            ObjectFactory.TypeEnum.Truck,//type
            new Vector3(209, 287, 0),//origin
            new Vector3(419, 287, 200),//collision
            new ArrayList { 
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.MISSION_OBJECT).get("truck"), 
                    new Rectangle(0, 0, 439, 287), 
                    0, 
                    new Vector2(219, 287))},
            new ArrayList { 
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.MISSION_OBJECT).get("truck"), 
                    new Rectangle(0, 0, 439, 287), 
                    0, 
                    new Vector2(219, 287))});

        //actual class data
//        Animation driving;
//        Animation sitting;

        /**
         * this is a dummy constructor.
         */
        protected Type() { }

        protected Type(ObjectFactory.TypeEnum type, Vector3 origin, Vector3 collision,
            ArrayList stasisFrames, ArrayList explosionFrames)
            : base(type, origin, collision, stasisFrames, explosionFrames)
        {
        }

        public static new DriveableObject.Type getType(ObjectFactory.TypeEnum type)
        {
            switch (type)
            {
                case ObjectFactory.TypeEnum.Car: return Car;
                case ObjectFactory.TypeEnum.Truck: return Truck;
            }
            return null;
        }
    }
}
